package com.itheima.web.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/8/29
 */

/**
 * Request获取请求数据--获取请求头数据
 * 	String getHeader(String name)
 * Request获取请求数据--获取请求体数据
 * 	ServletInputStream getInputStream()
 * 	BufferedReader getReader()
 */
@WebServlet("/demo04")
public class RequestDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求头中的user-agent（浏览器的版本信息）
        String agent = req.getHeader("user-agent");
        //Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
        // Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3872.400 QQBrowser/10.8.4455.400
        System.out.println(agent);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader br = req.getReader();
        String line = br.readLine();
        //username=zhagnsan&password=123
        System.out.println(line);
    }
}
